/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package zpsb.accounting.model;

import java.io.Serializable;
import java.math.BigDecimal;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author Michał
 */
@Entity
@Table(name = "products", catalog = "faktury", schema = "")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Product.findAll", query = "SELECT p FROM Product p"),
    @NamedQuery(name = "Product.findById", query = "SELECT p FROM Product p WHERE p.id = :id"),
    @NamedQuery(name = "Product.findByName", query = "SELECT p FROM Product p WHERE p.name = :name"),
    @NamedQuery(name = "Product.findByUnit", query = "SELECT p FROM Product p WHERE p.unit = :unit"),
    @NamedQuery(name = "Product.findByVatRate", query = "SELECT p FROM Product p WHERE p.vatRate = :vatRate"),
    @NamedQuery(name = "Product.findByUnitNetPrice", query = "SELECT p FROM Product p WHERE p.unitNetPrice = :unitNetPrice"),
    @NamedQuery(name = "Product.findByPkwiu", query = "SELECT p FROM Product p WHERE p.pkwiu = :pkwiu"),
    @NamedQuery(name = "Product.findByQuantity", query = "SELECT p FROM Product p WHERE p.quantity = :quantity")})
public class Product implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(nullable = false)
    private Integer id;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 500)
    @Column(nullable = false, length = 500)
    private String name;
    @Size(max = 50)
    @Column(length = 50)
    private String unit;
    @Basic(optional = false)
    @NotNull
    @Column(name = "vat_rate", nullable = false)
    private short vatRate;
    // @Max(value=?)  @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
    @Basic(optional = false)
    @NotNull
    @Column(name = "unit_net_price", nullable = false, precision = 10, scale = 2)
    private BigDecimal unitNetPrice;
    @Size(max = 100)
    @Column(length = 100)
    private String pkwiu;
    @Basic(optional = false)
    @NotNull
    @Column(nullable = false)
    private int quantity;
    @JoinColumn(name = "Invoices_ID", referencedColumnName = "id", nullable = false)
    @ManyToOne(optional = false)
    private Invoice invoice;

    public Product() {
    }

    public Product(Integer id) {
        this.id = id;
    }

    public Product(Integer id, String name, short vatRate, BigDecimal unitNetPrice, int quantity) {
        this.id = id;
        this.name = name;
        this.vatRate = vatRate;
        this.unitNetPrice = unitNetPrice;
        this.quantity = quantity;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getUnit() {
        return unit;
    }

    public void setUnit(String unit) {
        this.unit = unit;
    }

    public short getVatRate() {
        return vatRate;
    }

    public void setVatRate(short vatRate) {
        this.vatRate = vatRate;
    }

    public BigDecimal getUnitNetPrice() {
        return unitNetPrice;
    }

    public void setUnitNetPrice(BigDecimal unitNetPrice) {
        this.unitNetPrice = unitNetPrice;
    }

    public String getPkwiu() {
        return pkwiu;
    }

    public void setPkwiu(String pkwiu) {
        this.pkwiu = pkwiu;
    }

    public int getQuantity() {
        return quantity;
    }

    public void setQuantity(int quantity) {
        this.quantity = quantity;
    }

    public Invoice getInvoice() {
        return invoice;
    }

    public void setInvoice(Invoice invoicesID) {
        this.invoice = invoicesID;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Product)) {
            return false;
        }
        Product other = (Product) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "zpsb.accounting.model.Product[ id=" + id + " ]";
    }
    
}
